<template>
	<view class="signIn-container">
		<view class="signIn-container-num">已签到人数：<text class="number">{{signAll}}</text></view>
		<view class="signIn-container-prompt" >* 请实名填写，否则无法参与抽奖</view>
		<view class="signIn-container-form">
			<view class="text">姓名</view>
			<input type="text"  v-model="name" placeholder="请输入您的真实姓名"/>
		</view>
		<view type="button" value="签到" class="signIn-container-btn" @click="signIn">签到</view>
	</view>
</template>

<script>
	// 签到
	import signIn from "@/api/signIn.js"
	//获取中奖名单
	import login from "@/api/getList.js"
	//获取当前奖项信息，当前什么奖，上一个什么奖，下一个什么奖
	import getInfo from "@/api/getInfo.js"
	export default {
		name:"signIn",

		data() {
			return {
				name:""
			};
		},
		props:{
			signAll:{
				type:Number,
				required:true,
			}
		},
		async created(){
		},
		methods:{
			// 签到
			async signIn(){
				// 获取签到人姓名
				// console.log(this.name);
				
				// 去掉签到人姓名中所有空格
				const newName = this.name.replace(/\s/g,"");
			
				// 验证
				// console.log(newName)
				if(newName === ""){
					// 提示弹窗
					uni.showToast({
					  title: "请输入真实姓名",
					  icon: 'error',
					  duration:2000,
					  mask: true
					})
					this.name = ""
					// 清空姓名
					return;
				}
				
				
				
				
				
				// 本地化存储，后续无须再授权登录
				uni.setStorage({
				    key: 'isLogin',
				    data: true,
				});
				
				// 签到
				signIn().then(r => {
					if(r.data.code == "999999"){
						wx.showToast({
						  title: r.data.message,
						  icon: 'error',//当icon：'none'时，没有图标 只有文字
						  duration: 1000
						})
						return 
					}
					uni.setStorage({
						key:"sys_userInfo",
						data:r.data.data,
					})
					wx.showToast({
					  title: '签到成功！',
					  icon: 'success',//当icon：'none'时，没有图标 只有文字
					  duration: 1000
					})
					// 验证通过，跳转至首页
					uni.redirectTo({
						url:"/pages/home/home"
					})
				})
				
				
			}
		}
	}
</script>

<style scoped lang="scss">
// @import "@/static/iconfont/iconfont.css"; //自定义图标
.signIn-container{
	position: absolute;
	left:0px;
	top:50%;
	transform: translateY(-40%);
	@include myFlex()
	width:100%;
	.signIn-container-num{
		font-size:32rpx;
		color:#eee;
		margin-top:40rpx;
		margin-bottom:30rpx;
	}
	.signIn-container-prompt{
		font-size:28rpx;
		color:#FFCC00;
		margin-bottom:30rpx;
	}
	.signIn-container-form{
		@include flex(flex-start)
		width:80%;
		height:80rpx;
		background: #eee;
		border-radius:10rpx;
		color:#CC252C;
		font-size:28rpx;
		box-sizing: border-box;
		line-height:80rpx;
		margin-bottom:15rpx;
		.text{
			height:100%;
			width:20%;
			text-align:center;
			line-height:80rpx;
			box-sizing: border-box;
			border-right:1rpx solid #eee;
		}
		input{
			font-size:28rpx;
			padding-left:10rpx;
			color:#333;
		}
	}
	.signIn-container-btn{
		width:80%;
		height:80rpx;
		background: linear-gradient(0deg, #FFA239, #FFDF02);
		border-radius:10rpx;
		text-align:center;
		line-height:80rpx;
		color:#CC252C;
		font-size:28rpx;
		font-weight:bold;
	}
}
</style>
